
    public static void main(String[] args) {
        User user1 = new User(1,"a","a");
        User user2 = new User(12,"b","b");
        User user3 = new User(5,"b","b");
        List<User> list = Arrays.asList(user1,user2,user3);
        list.forEach(System.out::println);
        // 排序,jdk1.8新方法,reversed表示倒序
        list.sort(Comparator.comparing(User::getId).reversed());

//        List集合自带的排序方法
//        list.sort(new Comparator<User>() {
//            @Override
//            public int compare(User o1, User o2) {
//                return -o1.getId().compareTo(o2.getId());
//            }
//        });
        // Collections工具类中的排序方法
        Collections.sort(list, new Comparator<User>() {
            @Override
            public int compare(User o1, User o2) {
                return o1.getId().compareTo(o2.getId());
            }
        });
        list.forEach(System.out::println);
    }